<template>
	<view class="main">
		<view class="main">
			<chatSuitAudio ref="chatSuitAudio" :username="username" :chatType="chatType" @newAudioMsg="saveSendMsg"></chatSuitAudio>

			<chatMsglist ref="chatMsglist" :username="username" @msglistTap="normalScroll" @clickMsg="clickMsg" id="chat-msglist"></chatMsglist>
		</view>
		<chatInputbar
			ref="chatInputbar"
			:username="username"
			:chatType="chatType"
			@newTextMsg="saveSendMsg"
			@newImageMsg="saveSendMsg"
			@tapSendAudio="toggleRecordModal"
			@inputFocused="shortScroll"
			@inputBlured="normalScroll"
			v-show="!showEmediaInvite"
		></chatInputbar>
	</view>
</template>

<script>
let msgStorage = require('./msgstorage');
let msgType = require('./msgtype');
import chatMsglist from './msglist/msglist';
import chatInputbar from './inputbar/inputbar';
import chatSuitAudio from './inputbar/suit/audio/audio';
export default {
	data() {
		return {
			__comps__: {
				msglist: null,
				inputbar: null,
				audio: null
			},
			inputbarVisible: 'block',
			action: null,
			pubUrl: '',
			subUrl: '',
			showEmedia: false,
			showmultiEmedia: false,
			showEmediaInvite: false,
			emediaAction: null,
			multiEmediaVisible: 'block',
			confrId: '',
			confrMember: []
		};
	},

	components: {
		chatMsglist,
		chatInputbar,
		chatSuitAudio
	},
	props: {
		username: {
			type: Object,
			default: () => ({})
		},
		chatType: {
			type: String,
			default: msgType.chatType.SINGLE_CHAT
		}
	},
	computed: {
		computedUserName() {
			return this.username;
		}
	},

	methods: {
		toggleRecordModal() {
			this.$refs.chatSuitAudio.toggleRecordModal();
		},

		normalScroll() {
			this.$refs.chatMsglist.normalScroll();
			this.$refs.chatInputbar.cancelEmoji();
			this.$refs.chatInputbar.closeFunModal();
		},
		clickMsg(msg) {
			this.$emit('onClickInviteMsg', msg);
			console.log('点击消息上一级', msg);
		},
		shortScroll() {
			this.$refs.chatMsglist.shortScroll();
		},

		saveSendMsg(evt) {
			msgStorage.saveMsg(evt.msg, evt.type);
			this.$refs.chatInputbar.cancelEmoji();
			this.$refs.chatInputbar.closeFunModal();
		},

		getMore() {
			this.$refs.chatMsglist.getHistoryMsg();
		},
		onMakeVideoCall() {
			this.setData({
				showEmediaInvite: true,
				inputbarVisible: 'none',
				action: 'create'
				//showEmedia: true
			});
			console.log(this.showEmediaInvite);
		},
		onGoBack() {
			this.setData({
				showEmediaInvite: false,
				showmultiEmedia: true,
				multiEmediaVisible: 'block',
				inputbarVisible: 'none',
				confrMember: []
			});
		},
		onMakeAudioCall() {
			this.setData({
				showEmediaInvite: true,
				showmultiEmedia: false,
				inputbarVisible: 'none'
			});
		},
		onHangup() {
			this.setData({
				showEmediaInvite: false,
				showmultiEmedia: false,
				inputbarVisible: 'block'
			});
			getApp().globalData.confrId = '';
		}
	}
};
</script>
<style>
@import './chat.css';
</style>
